import React, { Component } from 'react'
import Parent from './parent'
export class index extends Component {
  state = {
    select:'',
    obj:[
      {color:'red',id:1},
      {color:'blue',id:2},
      {color:'green',id:3},
  ]
  }
  onchange = (e)=>{
    this.setState({select:e.target.value})
    console.log(e.target.value)
  }
  
  render() {
    return (
      <div>
        爷爷
        <select defaultValue={this.state.select} onChange={this.onchange}>
          {this.state.obj.map( item =><option key={item.id}>{item.color}</option>)}
        </select>
        {this.state.obj.map( item =><Parent key={item.id} color={item.color} select={this.state.select}/>)}
      </div>
    )
  }
}

export default index